//
//  ASTeacherCallNameViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/28.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASTeacherCallNameViewController.h"

@interface ASTeacherCallNameViewController ()

@end

@implementation ASTeacherCallNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initData];
    [self initView];
    
    // Do any additional setup after loading the view.
}

-(void)initData
{
    _teaCallNameInfoArr = [[NSMutableArray alloc] initWithObjects:@"选择科目名称", @"选择班级", nil];
}

-(void)initView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = YES;
    [_tableView registerClass:[AskForLeaTableViewCell class] forCellReuseIdentifier:NSStringFromClass([AskForLeaTableViewCell class])];
    [self.view addSubview:_tableView];
    
    
    //next
    
    //开始点名按钮
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, SubClassCellHeight*_teaCallNameInfoArr.count, CGRectGetWidth(self.view.bounds), 100)];
    footer.backgroundColor = [UIColor clearColor];
    
    UIButton* callNameBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //        callNameBtn.frame = CGRectMake(50, [UIScreen mainScreen].bounds.size.width/2+50,[UIScreen mainScreen].bounds.size.width-50*2,50);
    callNameBtn.frame = CGRectMake(50, 50,[UIScreen mainScreen].bounds.size.width-50*2,50);
    [callNameBtn setTitle:@"开始点名" forState:UIControlStateNormal];
    callNameBtn.layer.cornerRadius = 4.5;
    [callNameBtn addTarget:self action:@selector(callName) forControlEvents:UIControlEventTouchUpInside];
    
    [callNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    callNameBtn.backgroundColor = RGB(252, 120, 61);
    callNameBtn.enabled = YES;
    [footer addSubview:callNameBtn];
    _tableView.tableFooterView = footer;
}


//开始点名
-(void)callName
{
    ASTeacherCallNameConfirmViewController* callNameConfirmViewCtrl = [[ASTeacherCallNameConfirmViewController alloc] init];
    callNameConfirmViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:callNameConfirmViewCtrl animated:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_teaCallNameInfoArr count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AskForLeaTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AskForLeaTableViewCell class])];
    [cell setBackgroundColor:[UIColor clearColor]];
    cell.titleLabel.text = [_teaCallNameInfoArr objectAtIndex:indexPath.row];
    if (0 == indexPath.row) {
        cell.imgView.hidden = YES;
        if (!_subjectNameLab)
        {
            _subjectNameLab = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-20 - 150, 12+10, 150, cell.titleLabel.frame.size.height)];
            [_subjectNameLab setBackgroundColor:[UIColor clearColor]];
            _subjectNameLab.text = @"政治";
            _subjectNameLab.font = [UIFont systemFontOfSize:18];
            [_subjectNameLab setTextAlignment:NSTextAlignmentRight];
            _subjectNameLab.textColor = RGB(102, 102, 102);
            [cell addSubview:_subjectNameLab];
        }
        else
        {
            _subjectNameLab.text = @"政治";
        }
    }
    else
    {
        cell.imgView.hidden = NO;
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    BOOL bseleCla = NO;
    if (0 == indexPath.row) {
        bseleCla = NO;
    }
    
    if (1 == indexPath.row) {
        bseleCla = YES;
    }
    
    ASTeaSelectClassOrSubjectViewController* appForClassViewCtrl = [[ASTeaSelectClassOrSubjectViewController alloc] initWithSubOrClass:bseleCla];
    appForClassViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:appForClassViewCtrl animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
